<template>
  <div>
    <div class="pltxt" v-if="setName!=undefined">{{setName}} <span v-if="setUntil!=undefined">({{setUntil}})</span></div>
    <van-field v-model="lang_parent" clickable readonly @click="showPicker = true">
        <template #button>
          <van-button size="small" round @click="setLang($event)" class="setbtn">{{$t('Save')}}</van-button>
        </template>
    </van-field>
    <van-popup v-model="showPicker" round position="bottom">
      <van-picker show-toolbar 
        :columns="columns" 
        @cancel="showPicker = false" 
        @confirm="onConfirm"
        :confirm-button-text="$t('OK')"
        :cancel-button-text="$t('Cancel')" 
      />
    </van-popup>
  </div>
</template>

<script>

export default {
  props:['setName','columns','setValue','reg','setUntil'],
  data(){
    return {
      activeNames:[],
      showPicker:false,
      lang_parent:this.columns[this.setValue-1],
      langCode:this.setValue
    }
  },
  watch:{
    setValue(newVal){
      this.lang_parent=this.columns[newVal-1];
      this.langCode=newVal;
    }
  },
  methods: {
    onConfirm(value,i){
      this.lang_parent=value;
      this.showPicker=false;
      this.langCode=i+1;
      this.$emit('returnCode',i+1);
    },
    async setLang(e){
      e.stopPropagation();
      //处理数据
      let params={
        'optType':'setReg',
        'data':JSON.stringify({'num':1,'Data':[{'reg':this.reg,'val':this.langCode+''}]}),
        'pwd':sessionStorage.getItem('bdPwd')
      };
      this.comm.loadingShow();
      let data = await this.SETAPI.LocalIn(params);
      let newdata = data.substring(0, 1);
      if (newdata == "Y") {
        this.comm.toastSuccess();
        this.$emit('getFormData',this.langCode);
      }else {
        this.comm.toastFail();
      }
    }
  }
}
</script>

<style scoped lang="less">

</style>